package Prototype;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: 23种设计模式
 * @Package: Prototype
 * @ClassName: person
 * @Author: renhan
 * @Description:
 * @Date: 2020/11/14 8:54
 * @Version: 1.0
 */
public class Person implements Cloneable{
    //姓名
    private String name;
    //年龄
    private int age;
    //性别
    private String sex;

    private List<String> frends ;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                ", frends=" + frends +
                '}';
    }

    public Person clone(){
        try {
            Person person = (Person)super.clone();
            //深度拷贝
            List<String> frends = new ArrayList<>();
            for(String friend: this.getFrends()){
                frends.add(friend);
            }
            person.setFrends(frends);
            return person;
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<String> getFrends() {
        return frends;
    }

    public void setFrends(List<String> frends) {
        this.frends = frends;
    }
}
